home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PD Collection CD 1
/
PD Collection CD 1.iso
/
programer2
/
euclidlib
/
h
/
euclid
< prev
next >
Wrap
Text File
|
1992-04-18
|
16KB
|
550 lines
/**** euclid.h ****/
/* Definitions and functions to ease the use of Euclid from C.
* N.B. This module is compiled without stack checking -
* so you can pass pointers into flex blocks to these functions
* By Paul Field
* See !ReadMe file for distribution/modification restrictions
*/
#ifndef __euclid_h
#define __euclid_h
#include <stdlib.h>
#include "bool.h"
#include "os.h"
typedef int fix6,fix8,fix14,fix16; /* Fixpoint numbers : fixN has N binary places */
typedef enum euclid_id
{ eid_plane = 0x20, eid_vane, eid_path, eid_vanepath,
eid_solid = 0x30, eid_mesh, eid_sheet, eid_light = 0x3f,
eid_group = 0x40,
eid_transformation = 0x50, eid_matrixtransformation,
eid_colour = 0x60, eid_palette, eid_material
}euclid_id;
/**** Partial declarations of major structures ****/
typedef struct euclid_header euclid_header;
typedef struct euclid_plane euclid_plane;
typedef struct euclid_vane euclid_vane;
typedef struct euclid_path euclid_path;
typedef struct euclid_vanepath euclid_vanepath;
typedef struct euclid_solid euclid_solid;
typedef struct euclid_mesh euclid_mesh;
typedef struct euclid_sheet euclid_sheet;
typedef struct euclid_light euclid_light;
typedef struct euclid_group euclid_group;
typedef struct euclid_transformation euclid_transformation;
typedef struct euclid_matrixtransformation euclid_matrixtransformation;
typedef struct euclid_colourblock euclid_colourblock;
typedef struct euclid_palette euclid_palette;
typedef struct euclid_material euclid_material;
typedef struct euclid_film euclid_film;
/**** Declarations of structures ****/
typedef struct euclid_colour
{ union
{ unsigned int abscolour; /* 0xXMBBGGRR - x = 8 normal,9 transparent, A blank */
euclid_colourblock *relcolour;
}c;
}euclid_colour;
typedef struct euclid_coord
{ int x,y,z;
}euclid_coord;
typedef struct euclid_rotation
{ fix6 x,y,z;
}euclid_rotation;
typedef struct euclid_rgb
{ fix14 r,g,b;
}euclid_rgb;
struct euclid_header
{ unsigned int ecid;
unsigned int size;
unsigned int used;
void *base;
unsigned int headersize;
euclid_coord observertrans;
fix16 zoom;
euclid_rotation observerrot;
unsigned int perspective;
euclid_colour backgroundcol;
euclid_colour edgecol;
euclid_colour facecol;
void *root;
euclid_palette *palette;
euclid_material *materials;
fix14 ambient;
void *cache;
void *spritearea;
fix8 flatness;
};
typedef struct euclid_dataheader
{ char id; /* Actually a euclid_id but must fit in 8 bits */
char flags;
unsigned short variables;
}euclid_dataheader;
/**** 0x20 <= Id <= 0x2f ****/
struct euclid_plane
{ euclid_dataheader header;
euclid_coord point[255]; /* Actual size of array in header.variables */
};
struct euclid_vane
{ euclid_dataheader header;
struct euclid_vanevar
{ euclid_colour colour1, colour2;
euclid_coord point;
}var[255];
};
typedef enum euclid_pathtag
{ epathtag_move = 2, epathtag_control1 = 6,
epathtag_draw = 8, epathtag_control2 = 0x106,
epathtag_end = 0x206
}euclid_pathtag;
struct euclid_path
{ euclid_dataheader header;
struct euclid_pathvar
{ euclid_pathtag tag;
euclid_coord point;
}var[255];
};
struct euclid_vanepath
{ euclid_dataheader header;
struct euclid_vanepathvar
{ euclid_colour colour1, colour2;
euclid_pathtag tag;
euclid_coord point;
}var[255];
};
/**** 0x30 <= Id <= 0x3f ****/
struct euclid_solid
{ euclid_dataheader header;
char name[12];
euclid_coord boundingcentre;
unsigned int boundingradius;
struct euclid_solidvar
{ euclid_colour colour;
euclid_plane *plane;
}var[255];
};
typedef enum euclid_facetflag
{ efacetflag_rectangles, efacetflag_nofacets,
efacetflag_triangles1, efacetflag_triangles2
}euclid_facetflag;
typedef enum euclid_meshflags
{ emeshflags_facets = 0x00,
emeshflags_cylindrical = 0x04,
emeshflags_toroidal = 0x08,
emeshflags_firstvane = 0x10,
emeshflags_lastvane = 0x20,
emeshflags_intermediatevanes = 0x40
}euclid_meshflags;
struct euclid_mesh
{ euclid_dataheader header;
char name[12];
euclid_coord boundingcentre;
unsigned int boundingradius;
euclid_meshflags flags;
struct euclid_meshvar
{ euclid_colour colour;
euclid_vane *vane;
}var[255];
};
typedef enum euclid_sheetflags
{ esheetflags_nofacets = 0x001,
esheetflags_notexture = 0x002,
esheetflags_wraponu = 0x004,
esheetflags_wraponv = 0x008,
esheetflags_uis0 = 0x010,
esheetflags_uis1 = 0x020,
esheetflags_vis0 = 0x040,
esheetflags_vis1 = 0x080,
esheetflags_ureversed = 0x100,
esheetflags_vreversed = 0x200,
esheetflags_firstpath = 0x300,
esheetflags_secondpath = 0x400
}euclid_sheetflags;
typedef enum euclid_blendfn
{ eblendfn_cylindrical, eblendfn_sum
}euclid_blendfn;
struct euclid_sheet
{ euclid_dataheader header;
char name[12];
euclid_coord boundingcentre;
unsigned int boundingradius;
euclid_sheetflags flags;
euclid_blendfn blendfn;
euclid_coord blendaux;
euclid_colour backgroundcol;
void *texture;
struct euclid_sheetvar
{ euclid_colour colour;
euclid_path *path;
}var[255];
};
typedef enum euclid_lightflags
{ elightflags_off = 1, elightflags_directional = 2
}euclid_lightflags;
struct euclid_light
{ euclid_dataheader header;
euclid_rgb intensities;
euclid_lightflags flags;
int reserved[2]; /* Must be 0 */
};
/**** 0x40 <= Id <= 0x4f ****/
struct euclid_group
{ euclid_dataheader header;
char name[12];
euclid_coord boundingcentre;
unsigned int boundingradius;
struct euclid_groupvar
{ euclid_transformation *transformation;
void *grouporprim;
}var[255];
};
/**** 0x50 <= Id <= 0x5f ****/
struct euclid_transformation
{ euclid_dataheader header;
euclid_coord translation;
fix16 scale;
euclid_rotation rotation;
};
struct euclid_matrixtransformation
{ euclid_dataheader header;
euclid_coord translation;
fix16 scale;
fix14 matrix[3][3];
};
/**** 0x60 <= Id <= 0x6f ****/
struct euclid_colourblock
{ euclid_dataheader header;
unsigned int flags; /* Should be 0 for now */
char spritename[12];
};
typedef enum euclid_palettetype
{ epalettetype_monochrome=1, epalettetype_polychrome, epalettetype_256
}euclid_palettetype;
struct euclid_palette
{ euclid_dataheader header;
euclid_palettetype type;
unsigned int maxintensity;
unsigned int lines;
struct euclid_palettevar
{ int dontknow[16]; /* I'm not sure what should be here */
}var[255];
};
struct euclid_material
{ euclid_dataheader header;
struct euclid_materialvar
{ char name[12];
fix14 ambient;
fix14 diffuse;
fix14 spectral;
int shine;
int reserved[4]; /* Must be 0 */
}var[255];
};
/**** Definitions for Euclid Films ****/
typedef enum euclid_compression
{ ecompression_runlength, ecompression_lzw /* I think 0 is run-length - may be wrong */
}euclid_compression;
typedef enum euclid_filmflags
{ efilmflags_filmtype, efilmflags_rewind = 4
} euclid_filmflags;
typedef enum euclid_filmtype
{ efilmtype_normal, efilmtype_delta, efilmtype_deltafixed
}euclid_filmtype;
struct euclid_film
{ unsigned int length;
char name[12];
unsigned int startoffset;
unsigned int width;
unsigned int height;
unsigned int mode;
euclid_compression technique;
euclid_filmflags flags;
};
/**** Functions ****/
/* Handy macros for converting doubles to fixed point integers and vice versa */
#define tofixN(d,n) ((int)((d)*(1<<(n))+0.5))
#define tofix6(d) tofixN(d,6)
#define tofix8(d) tofixN(d,8)
#define tofix14(d) tofixN(d,14)
#define tofix16(d) tofixN(d,16)
#define fromfixN(i,n) ((double)(i)/(1<<(n)))
#define fromfix6(i) fromfixN(i,6)
#define fromfix8(i) fromfixN(i,8)
#define fromfix14(i) fromfixN(i,14)
#define fromfix16(i) fromfixN(i,16)
/* Handy functions for de/constructing absolute colours */
#define euclid_makecolour(m,r,g,b) (((m)<<24)|((b)<<16)|((g)<<8)|(r))
void euclid_getcolour(unsigned int c, unsigned int *m,
unsigned int *r, unsigned int *g, unsigned int *b);
/* Breaks an absolute colour 'c' down into its component parts and returns
* them in 'm','r','g' and 'b'.
*/
/* Euclid uses strings that terminate with a '0d' character while C uses '0' terminated
* characters. The following two function convert between the two.
*/
void euclid_setname(char *name, const char *cstring);
/* Copies 'cstring' to 'name' in the euclid data structure.
*/
void euclid_getname(char *cstring, const char *name);
/* Copies 'name' (in the euclid data structure) to 'cstring'.
*/
/**** Main interface functions for euclid module ****/
typedef enum euclid_initflags
{ einitflags_blackonwhite = 1,
einitflags_perspectiveplus = 2
}euclid_initflags;
os_error *euclid_initialise(euclid_initflags flags, euclid_header *structure,
size_t size, int *version);
/* Initialises a picture structure.
* If flags == -1 this updates the euclid module's current block pointer.
* On return 'version' contains the module version number x 100.
* You can pass NULL in 'version' if you are not interested in its value.
*/
typedef unsigned int euclid_drawstyle; /* Can't do this with an enum, needs unsigned */
#define edrawstyle_wireframe 0x00000001
#define edrawstyle_mainstyle 0x00000002
#define edrawstyle_monochrome 0x00000080
#define edrawstyle_systemvisible 0x00000100
#define edrawstyle_lightson 0x00000200
#define edrawstyle_frontlighton 0x00000400
#define edrawstyle_continuetimedout 0x00000800
#define edrawstyle_timeout 0x00001000 /* 9 bits - timeout in centiseconds */
#define edrawstyle_absolutepolygons 0x04000000
#define edrawstyle_vdudrivers 0x08000000
#define edrawstyle_oldpalette 0x10000000
#define edrawstyle_drawfileinfo 0x20000000
#define edrawstyle_vduvars 0x40000000
#define edrawstyle_preprocess 0x80000000
typedef enum euclid_mainstyle
{ emainstyle_facesonly, emainstyle_facesandedges, emainstyle_raytrace
}euclid_mainstyle;
typedef enum euclid_drawflags
{ edraw_flags_noshadows
}euclid_drawflags;
typedef struct euclid_drawinfo
{ unsigned int nexty, nextx;
unsigned int memory;
unsigned int voxels;
unsigned int pixels;
unsigned int rays;
unsigned int rayhits;
unsigned int intersectiontests;
unsigned int voxelsvisited;
unsigned int polygonswhensplit;
unsigned int polygons;
char depth;
char simplicity;
char maxrecursion;
char flags; /* Type should be 'euclid_drawflags' but it must fit in 1 byte */
fix14 cutoff;
}euclid_drawinfo;
os_error *euclid_draw(euclid_drawstyle style, euclid_header *structure,
int xoffset, int yoffset, const char *camera, void *vduvars,
BOOL *timedout, euclid_drawinfo **infoblock);
/* See !Euclid.Docs.SWIs and !ArcLight.Docs.RayTrace
* (camera == NULL - no camera).
* You can pass NULL in 'timedout' and 'infoblock' if you are not interested in their
* values. Warning : if there is no timeout then '*timedout' will be undefined
* You may find it easier to use the 'edraw' module.
*/
os_error *euclid_load(BOOL postprocessonly, euclid_header *structure,
const char *filename);
/* See Docs.SWIs
*/
os_error *euclid_save(euclid_header *structure, const char *filename);
/* See Docs.SWIs
*/
os_error *euclid_append(BOOL postprocess, euclid_header *structure,const char *filename);
/* See Docs.SWIs
*/
os_error *euclid_find(euclid_header *structure, const char *name,
char **leaf, euclid_transformation **transformation,
euclid_matrixtransformation **matrix,
euclid_matrixtransformation **inverse,
void **entry,
euclid_group **group);
/* See Docs.SWIs
* You can pass NULL in any of the 'output' variables if you are not interested in
* their values.
*/
os_error *euclid_list(void **object, euclid_header *structure, euclid_id id);
/* Finds the next object of type 'id' starting from 'object'.
* If id==0 all types are found.
*/
/* Not much point interfacing to Euclid_Set and Euclid_Show - you can use the
* structures defined above to access the appropriate data.
*
* The same applies for Euclid_Translate, Euclid_Rotate and Euclid_Zoom.
*/
os_error *euclid_create(unsigned int children, euclid_header *structure, euclid_id id,
void *newobject);
/* Creates an object and returns a pointer to it in 'newobject'.
* BE VERY CAREFUL. Your fourth parameter should be a pointer to a pointer e.g.
* { euclid_mesh *mesh;
* euclid_create(0,structure,eid_mesh,&mesh);
* }
* For more details see Docs.SWIs
*/
os_error *euclid_destroy(euclid_header *structure, void *object);
/* See Docs.SWIs
*/
os_error *euclid_insert(unsigned int entry, euclid_header *structure, void *object,
void *newentry);
/* BE VERY CAREFUL. Your fourth parameter should be a pointer to a pointer e.g.
* { euclid_mesh *mesh;
* euclid_insert(0,structure,object,&mesh);
* }
* See Docs.SWIs
*/
os_error *euclid_delete(unsigned int entry, euclid_header *structure, void *object);
/* See Docs.SWIs
*/
os_error *euclid_getsystemmaterials(euclid_material **materials);
/* On return, 'materials' points to the system materials table.
* This is Euclid_MiscOp 2
*/
os_error *euclid_imagesmooth(int reserved_settozero);
/* Smooths the image in the current graphics window.
* This is Euclid_MiscOp 3
*/
os_error *euclid_blocksize(euclid_id id, unsigned *headersize, unsigned *variablesize);
/* Returns values for the size of the fixed and variable parts of a block.
* This is Euclid_MiscOp 4
*/
os_error *euclid_ditherpattern(unsigned colour, unsigned *bytes);
/* Returns in 'bytes' the byts to be used on the screen to represent 'colour'.
* (You can use 'euclid_makecolour' to create the colour value)
* This is Euclid_MiscOp 5
*/
os_error *euclid_invalidatepalettecache(void);
/* Call if your application recieves a 'palette changed' message.
* This is Euclid_MiscOp 6
*/
os_error *euclid_setdrawparams(char depth, char simplicity, char maxrecursion,
euclid_drawflags, fix14 cutoff);
/* See !Arclight.Docs.Raytrace - This is Euclid_MiscOp 7
*/
os_error *euclid_closedown(void);
/* See Docs.SWIs
*/
os_error *euclid_compress(euclid_compression type, void **data, void **screenbase);
/* See Docs.SWIs
*/
os_error *euclid_expand(euclid_compression type, void **data, void **screenbase);
/* See Docs.SWIs
*/
#endif